package com.smarthouse.controller;

import com.smarthouse.model.ApiResponse;
import com.smarthouse.service.TextRecognitionService;
import com.sun.tools.jconsole.JConsoleContext;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.sound.midi.Soundbank;
import java.util.Map;

@Tag(name = "文字识别接口")
@RestController
@RequestMapping("/text")
@CrossOrigin
public class TextRecognitionController {

    private final TextRecognitionService textRecognitionService;

    public TextRecognitionController(TextRecognitionService textRecognitionService) {
        this.textRecognitionService = textRecognitionService;
    }

    @Operation(summary = "验证文本")
    @PostMapping("/verify")
    public ApiResponse<Boolean> verifyText(@RequestBody Map<String, String> request) {
        try {
            String text = request.get("content");
            System.out.println("text: " + text);
            if (text == null || text.trim().isEmpty()) {
                return ApiResponse.error("文本不能为空");
            }
            boolean isValid = textRecognitionService.verifyText(text.trim());
            return ApiResponse.success(isValid);
        } catch (Exception e) {
            return ApiResponse.error(e.getMessage());
        }
    }
} 